An important requirement for a multiprocessor computer system is for multiple devices to be able to share a common resource. Typically, a synchronization mechanism is used to coordinate multiple accesses for the shared resource in order to ensure that one device obtains the shared resource at a given time.
An example of such a synchronization mechanism is an atomic instruction, such as a test-and-set instruction or a read-modify-write instruction. The atomic instruction operates on a lock variable or semaphore that represents the shared resource. Only one device is able to obtain access to the lock variable at a time thereby synchronizing access to the shared resource. Often, a device wants to write a value into the lock variable once it obtains access to it. The atomic instruction allows the device to both read the value of the lock variable and to write another value to the lock variable at the same time.
Atomic instructions are typically implemented using a bus lock mechanism or 25 a cache coherency mechanism. In the bus lock mechanism, the bus is the only path to the memory location of the lock variable. A device obtains exclusive access to the bus thereby locking out all other devices to the memory location of the lock variable.
A cache coherency mechanism ensures that the contents of a particular memory location stored in any cache and in main memory remain coherent. In one such cache coherency mechanism, a protocol is used that updates the lock variable in one location in response to changes made to the lock variable in a second location. In another cache concurrency mechanism, another protocol is used that associates status tags with the lock variable that reflect the staleness of the lock variable when a copy of the lock variable is contained elsewhere. In this manner, a device is prevented from reading a copy of the lock variable that does not reflect its current value.
In some multiprocessor computer systems, a bus lock mechanism or a cache coherency mechanism may not be feasible. The shared resource and a device contending for the shared resource may not be connected by a common bus. In addition, the shared resource may not be cached thereby not subject to a cache coherency mechanism. For these types of computer systems, there is a need for a synchronization mechanism that can ensure atomic access to the shared resource.